var express = require('express');
var db = require('./db.js')

var router = express.Router()
var bodyParser = require('body-parser');
var md5 = require('md5-nodejs');
var urlencodedParser = bodyParser.urlencoded({ extended: false })

var multer = require('multer');


//详情页获取评论
router.get('/get-discuss',async function(req,res){
    let { bdid }=req.query
    let sql =`select d.*,u.name from discuss as d,users as u where d.uid=u.id and d.bdid='${bdid}'`
    let r =await db.doSql(sql)
    res.send(db.heal(r))
})
// 详情页保存评论
router.post('/save-discuss',urlencodedParser,async function(req,res){
    let { content, uid, bdid } = req.body
    var sql = `insert into discuss (content, uid, bdid) values ('${content}','${uid}','${bdid}')`;
    let r =await db.doSql(sql)
    res.send(db.heal(r))
})


module.exports = router